<?php
	/*
		PandaForum: PHP Forum Engine
		
		Jesse Gill, 0108377707
	*/
	
	require_once('./src/classes/Page.php');
	
	$page = new Page('UCP');
	
	$page->print_header();
	
	// Only users can access the user control panel
	if (! $page->curUser->has_rank("User", $page->connection))
		die('You must be a user to access this page.');
	
	$stats_array = array();
	$id = $page->curUser->id;
	$display_rank = $page->curUser->displayed_rank;
	
	$result = $page->connection->get_result("SELECT * FROM ranks WHERE id=$display_rank");
	$obj = $result->fetch_object();
	$stats_array['Displayed rank:'] = ($obj) ? $obj->name : 0;
	if ($result)
		$result->free();
	
	$result = $page->connection->get_result("SELECT * FROM user_friends WHERE userid=$id");
	$stats_array['Friends:'] = ($result) ? $result->num_rows : 0;
	if ($result)
		$result->free();
	
	$result = $page->connection->get_result("SELECT * FROM user_enemies WHERE userid=$id");
	$stats_array['Enemies:'] = ($result) ? $result->num_rows : 0;
	if ($result)
		$result->free();
	
	$result = $page->connection->get_result("SELECT * FROM topic WHERE creatorid=$id");
	$stats_array['Topics started:'] = ($result) ? $result->num_rows : 0;
	if ($result)
		$result->free();
	
	$result = $page->connection->get_result("SELECT * FROM post WHERE posterid=$id");
	$stats_array['Number of posts:'] = ($result) ? $result->num_rows : 0;
	if ($result)
		$result->free();
?>
	<link href='src/css/acp.css' rel='stylesheet' type='text/css' />
	<script type="text/javascript" src="src/js/ajax_functions_acp.js"></script>
	
	<h1 class="pageheading">User Control Panel</h1>
	
	<table>
		<?php
			// Generate the statistics table rows
			foreach ($stats_array as $text => $value)
			{
		?>
				<tr>
					<td><?php echo $text; ?></td>
					<td><?php echo $value; ?></td>
				</tr>
		<?php
			}
		?>
	</table>
<?php
	$page->print_ucp_nav();
	$page->print_footer();
?>